{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [],
   "source": [
    "import time\n",
    "import random\n",
    "from multiprocessing import Process\n",
    "\n",
    "def piao(name):\n",
    "    print(\"%s piaoing \"%name)\n",
    "    \n",
    "    print('%s piao end'%name)\n",
    "if __name__=='__main__':\n",
    "    for i in range(10):\n",
    "        p=Process(target=piao,args=('fujun',))\n",
    "        p.start()\n",
    "    \n",
    "   \n",
    "    \n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "主线程\n"
     ]
    }
   ],
   "source": [
    "import time \n",
    "import random \n",
    "from multiprocessing import Process\n",
    "class Piao(Process):\n",
    "    def __init__(self,name):\n",
    "        super().__init__()\n",
    "        self.name=name\n",
    "    def run(self):\n",
    "        print('%s piaoing '%self.name)\n",
    "        time.sleep(random.randrange(2,4))\n",
    "        print('%s piao end'%self.name)\n",
    "if __name__=='__main__':\n",
    "    p1=Piao('fujun')\n",
    "    p2=Piao('fuwen')\n",
    "    p1.start()\n",
    "    p2.start()\n",
    "    print('主线程')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "ok\n"
     ]
    }
   ],
   "source": [
    "from multiprocessing import Process\n",
    "import time\n",
    "import random\n",
    "class Piao(Process):\n",
    "    def __init__(self,name):\n",
    "        self.name=name\n",
    "        super().__init__()\n",
    "    def run(self):\n",
    "        print('%s is piaoing'%self.name)\n",
    "        time.sleep(random.randrange(1,3))\n",
    "        print('%s piao end'%self.name)\n",
    "if __name__=='__main__':\n",
    "    p1=Piao('jk')\n",
    "    p2=Piao('kl')\n",
    "    p1.start()\n",
    "    p2.start()\n",
    "    p1.join()\n",
    "    p2.join()\n",
    "    print('ok')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [],
   "source": [
    "import time\n",
    "import random\n",
    "from multiprocessing import Process\n",
    "\n",
    "def piao(name):\n",
    "    print(\"%s piaoing \"%name)\n",
    "    \n",
    "    print('%s piao end'%name)\n",
    "if __name__=='__main__':\n",
    "    for i in range(10):\n",
    "        p=Process(target=piao,args=('fujun',))\n",
    "        p.start()\n",
    "        "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "还是\n",
      "248\n",
      "还是\n",
      "6336\n",
      "还是\n",
      "13060\n",
      "还是\n",
      "6340\n",
      "还是\n",
      "15132\n",
      "还是\n",
      "9620\n",
      "还是\n",
      "6240\n",
      "还是\n",
      "10176\n",
      "还是\n",
      "16852\n",
      "还是\n",
      "2156\n"
     ]
    }
   ],
   "source": [
    "from multiprocessing import Process\n",
    "import time,random\n",
    "class piao(Process):\n",
    "    def __init__(self):\n",
    "        super().__init__()\n",
    "    def run(self):\n",
    "        print(1)\n",
    "        time.time(random.randrange(1,3))\n",
    "        print(0)\n",
    "if __name__=='__main__':\n",
    "    for i in range(10):\n",
    "        p=piao()\n",
    "        p.start()\n",
    "        print('还是')\n",
    "        print(p.pid)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {},
   "outputs": [],
   "source": [
    "from multiprocessing import Process\n",
    "import time,random\n",
    "class piao(Process):\n",
    "    def __init__(self):\n",
    "        super().__init__()\n",
    "    def run(self):\n",
    "        print(1)\n",
    "        time.sleep(2)\n",
    "        print(0)\n",
    "if __name__=='__main__':\n",
    "    p=piao()\n",
    "   \n",
    "    p.demon=True\n",
    "    p.start()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.1"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
